package com.java2207.group1.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java2207.group1.common.LayuiPageVo;
import com.java2207.group1.mapper.RoomMapper;
import com.java2207.group1.pojo.Room;
import com.java2207.group1.service.RoomService;
import com.java2207.group1.vo.consult.BarVo;
import com.java2207.group1.vo.consult.PieVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author :xs
 * @date : 2022/7/26
 */
@Service("roomService")
public class RoomServiceImpl implements RoomService {


   @Autowired
   private RoomMapper roomMapper;


    @Override
    public LayuiPageVo<Room> roomPage(Map<String, Object> params) {
        int page = Integer.parseInt(params.get("page") + "");
        int limit = Integer.parseInt(params.get("limit") + "");
        PageHelper.startPage(page, limit);
        List<Room> rooms= roomMapper.RoomPageData(params);
        //mybatis的分页数据结构
        PageInfo<Room> roomPageInfo = new PageInfo<>(rooms);
        LayuiPageVo<Room> roomLayuiPageVo = new LayuiPageVo<>();
        roomLayuiPageVo.setCode(0);
        roomLayuiPageVo.setMsg("分页列表数据");
        roomLayuiPageVo.setCount(roomPageInfo.getTotal());
        roomLayuiPageVo.setData(roomPageInfo.getList());



        return roomLayuiPageVo;
    }

    @Override
    public int deleteRoom(Integer id) {
       int i = roomMapper.deleteRoom(id);
        return i;
    }

    @Override
    public int remove(String ids) {
       String [] arrId = ids.split(",");
        return roomMapper.remove(arrId);
    }

    @Override
    public int addRoom(Room room) {
        int i = roomMapper.addRoom(room);
        return i;
    }

    @Override
    public int updataRoom(Room room) {
        int i = roomMapper.updateRoom(room);
        return i;
    }

    @Override
    public List<PieVo> TypeNameData() {
       List<PieVo>list = roomMapper.TypoNamePieData();
        return list;
    }

    @Override
    public List<BarVo> TypeNameBarData() {
       List<BarVo>list = roomMapper.TypeNameBarDate();
        return list;
    }
}
